/**
 *
 */
package com.hiultra.common.utils;

import com.hiultra.common.core.domain.entity.ArcCabinet;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author ls
 *
 */
public class ArcUtil {
	private static long orderNum = 0L;
	private static String date;
	/**
	 * 生成分类编号
	 *
	 * @return
	 */
	public static synchronized String getOrderNo() {
		String str = new SimpleDateFormat("yyMMddHHmm").format(new Date());
		if (date == null || !date.equals(str)) {
			date = str;
			orderNum = 0L;
		}
		orderNum++;
		long orderNo = Long.parseLong((date)) * 10000;
		orderNo += orderNum;
		return orderNo + "";
	}

	/**
	 * 两位下级编码
	 */
	public static synchronized String get00NextCode(String code) {
		if (code.length() < 2) {
			return "00";
		}
		String temps = code.substring(code.length() - 2, code.length());
		int tempi = Integer.parseInt(temps);
		if (tempi == 99) {
			return "00";
		} else {
			return String.format("%02d", tempi);
		}

	}

	/**
	 * 三位位下级编码
	 */
	public static synchronized String get000NextCode(String code) {
		if (code.length() < 2) {
			return "000";
		}
		String temps = code.substring(code.length() - 2, code.length());
		int tempi = Integer.parseInt(temps);
		if (tempi == 999) {
			return "000";
		} else {
			return String.format("%03d", tempi + 1);
		}
	}
	public static synchronized String formatCode(int code) {

		return String.format("%03d", code);
	}

	/**
	 * MD5验证方法
	 *
	 * @param text 明文
	 * @param key  密钥
	 * @param md5  密文
	 * @return true/false
	 * @throws Exception
	 */
	public static boolean verify(String text, Integer key, String md5) throws Exception {
		// 根据传入的密钥进行验证
		String md5Text = DigestUtils.md5Hex(text + "-" + key);
		if (md5Text.equalsIgnoreCase(md5)) {
			return true;
		}
		return false;
	}

	/**
	 * 根据年月日生成十二位不重复编码
	 *
	 * @return
	 */
	public static synchronized String getOrderNoTo12() {
		String str = new SimpleDateFormat("yyMMddHHmm").format(new Date());
		if (date == null || !date.equals(str)) {
			date = str;
			orderNum = 0L;
		}
		orderNum++;
		long orderNo = Long.parseLong((date)) * 100;
		orderNo += orderNum;
		return orderNo + "";
	}
}
